package com.klun.likou;

public class Solution11 {
	public static void main(String[] args) {
		// 生成随机不重复数组
		// int[] height = GenUtil.genIntArrDiff(1000, 1, 2000);
		int[] height = {1, 8, 6, 2, 5, 4, 8, 3, 7};
		int i = maxArea(height);
		System.out.println(i);
	}

	/**
	 * 给出一个 32 位的有符号整数，你需要将这个整数中每位上的数字进行反转
	 *
	 * @return
	 */
	public static int maxArea(int[] height) {
		// 双指针一次遍历
		int length = height.length;
		int area = 0;
		for (int i = 0, j = length - 1; i <= j; ) {
			int lVal = height[i];
			int hVal = height[j];
			int min = Math.min(lVal, hVal) * (j - i);
			if (min > area) {
				area = min;
			}
			if (lVal > hVal) {
				j--;
			} else {
				i++;
			}
		}
		return area;
	}
}
